<?php
/**
 * Formular zmeny hesla administratorom
 * @author Tomas Srna
 * @package bakalarka
 */

class PasswdForm extends Form 
{
	public function __construct(Template $template, $values = NULL, 
		$action = NULL, $method = 'POST')
	{
		parent::__construct($template, $values, $action, $method);
		
		// name, label, [type], [class], [hint], [$options]
		$this->items = array(
			new Element('password', L::selected()->password, "password", 
						"required"),
			new Element('confirmation', L::selected()->confirmation, 
						"password", "required"),
		);
	}
	
	/**
	 * Pokial nam zakladne kontroly nestacia, mozme si pridat vlastne
	 * specificke pre dany formular
	 */
	public function validate()
	{
		parent::validate();
		
		if($this->getValue('password') != $this->getValue('confirmation') &&
			!$this->getError('confirmation'))
		{
			$this->setError('confirmation', 
				L::selected()->passwordConfirmation);
		}
		
		if(count($this->errors) > 0)
			return false;
		
		return true;
	}
}
